package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.system.domain.Car;
import com.ruoyi.system.domain.Worker;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Finance;
import com.ruoyi.system.service.IFinanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2024-04-09
 */
@RestController
@RequestMapping("/system/finance")
public class FinanceController extends BaseController
{
    @Autowired
    private IFinanceService financeService;

    /**
     *
     *
     *
     * 查询【请填写功能名称】列表
     */
    @Log(title = "财务管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:finance:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Finance> util = new ExcelUtil<>(Finance.class);
        List<Finance> financeList = util.importExcel(file.getInputStream());
        String message = financeService.importFinances(financeList, updateSupport);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<Finance> util = new ExcelUtil<Finance>(Finance.class);
        util.importTemplateExcel(response, "财务数据");
    }
    @PreAuthorize("@ss.hasPermi('system:finance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Finance finance)
    {
        startPage();
        List<Finance> list = financeService.selectFinanceList(finance);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('system:finance:list')")
    @Anonymous
    @GetMapping("/charts")
    public List<Finance> charts(Finance finance)
    {
        return financeService.selectFinanceList(finance);
    }


    @Anonymous
    @GetMapping("/frontList")
    public AjaxResult getFinanceList(Finance finance)
    {
        return success(financeService.selectFinanceList(finance));
    }
    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:finance:export')")
    @Log(title = "财务数据导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Finance finance)
    {
        List<Finance> list = financeService.selectFinanceList(finance);
        ExcelUtil<Finance> util = new ExcelUtil<Finance>(Finance.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:finance:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId)
    {
        return success(financeService.selectFinanceByFId(fId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:finance:add')")
    @Log(title = "财务数据添加", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Finance finance)
    {
        return toAjax(financeService.insertFinance(finance));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:finance:edit')")
    @Log(title = "修改财务数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Finance finance)
    {
        return toAjax(financeService.updateFinance(finance));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:finance:remove')")
    @Log(title = "删除财务数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds)
    {
        return toAjax(financeService.deleteFinanceByFIds(fIds));
    }
}
